using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using TMS.Application.Common.Interface;

namespace TMS.Api.Session
{
    public class SessionUserService: ISessionService
 	    {
        private readonly IHttpContextAccessor _contextAccessor;
 
       public SessionUserService(IHttpContextAccessor contextAccessor)
        {
            _contextAccessor = contextAccessor;
         }
 
        public string? UserId
        {
           get
            {
                // 从token中拿到对应的值
                var userIdString = _contextAccessor.HttpContext?.User.FindFirstValue("UserId");
                 if (userIdString == null)
                 {
	                    return null;
                 }
	                else
                 {
	                    // var userIdGuid = new Guid(userIdString);
                    return userIdString;
	                }
 
            }
 
        }
 
        public string? UserName
        {
            get
	            {
                 // 从token中拿到对应的值
                var username = _contextAccessor.HttpContext?.User.FindFirstValue("UserName");
                return username;
             }
         }
     }
}